<?
class View
{
    private static $variable = array(
                'result' => null,
                'msg' => array(),
                'data' => array()
            );
    
    /*
     * 重置View数据
     */
	public static function restore()
	{
        $variable = array(
            'result' => null,
            'msg' => array(),
            'data' => array()
        );
	}
	
    /*
     * 设置返回到页面结果
     */
	public static function setResult($_result)
	{
		self::$variable['result'] = $_result;
	}
    
    /*
     * 设置返回到页面的消息
     */
	public static function setMsg($_msg)
	{
		array_push(self::$variable['msg'], $_msg);
	}
    
    /*
     * 设置返回到页面的数据
     */
	public static function setData($_key, $_data)
	{
		self::$variable['data'][$_key] = $_data;
	}
    
	/*
     * 输出页面或JSON结果
     */
	public static function draw($_view_name)
	{
        if(is_ajax)
        {
            echo json_encode(self::$variable);
            return;
        }
        
        if(is_jsonp)
        {
			echo $_REQUEST['callback'] . '(' . json_encode(self::$variable) . ');';
            return;
        }
        
        extract(self::$variable, EXTR_OVERWRITE);
        
        $path = path_prefix_application . 'template/' . application_name . '/'. $_view_name . '.html';
        
        include $path;
	}
}

?>